package com.yanqu.road.entity.activity.dafuweng;

import com.yanqu.road.entity.DataObject;
import com.yanqu.road.entity.FieldTypeAnnotation;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@FieldTypeAnnotation(tableName = "t_u_dfw_union_data")
public class DFWUnionData extends DataObject {

    @FieldTypeAnnotation(desc = "商会UID")
    private String unionUid = "";

    @FieldTypeAnnotation(desc = "活动ID")
    private int activityId;

    @FieldTypeAnnotation(desc = "商会活动分组ID")
    private int groupId;

    @FieldTypeAnnotation(desc = "今日现金礼包购买次数")
    private Map<Long, Integer> buyTimesMap = new ConcurrentHashMap<>();

    @FieldTypeAnnotation(desc = "今日商会返利领取人员ID")
    private Map<Integer, List<Long>> rebateUserList = new ConcurrentHashMap<>();

    @FieldTypeAnnotation(desc = "道具收集数量（道具ID，数量）")
    private Map<Integer, Integer> collectCountMap = new ConcurrentHashMap<>();

    @FieldTypeAnnotation(desc = "加成")
    private int addition;

    @FieldTypeAnnotation(desc = "加成恢复时间")
    private long additionRecoveryTime;

    @FieldTypeAnnotation(desc = "重置时间")
    private long lastResetTime;

    public long getLastResetTime() {
        return lastResetTime;
    }

    public void setLastResetTime(long lastResetTime) {
        if (this.lastResetTime != lastResetTime) {
            this.lastResetTime = lastResetTime;
            setUpdateOption();
        }
    }

    public void setUnionUid(String unionUid) {
        this.unionUid = unionUid;
    }

    public void setActivityId(int activityId) {
        this.activityId = activityId;
    }

    public void setBuyTimesMap(Map<Long, Integer> buyTimesMap) {
        this.buyTimesMap = buyTimesMap;
        setUpdateOption();
    }

    public void setRebateUserList(Map<Integer, List<Long>> rebateUserList) {
        this.rebateUserList = rebateUserList;
        setUpdateOption();
    }

    public void setCollectCountMap(Map<Integer, Integer> collectCountMap) {
        this.collectCountMap = collectCountMap;
        setUpdateOption();
    }

    public void setAddition(int addition) {
        if (addition != this.addition) {
            this.addition = addition;
            setUpdateOption();
        }
    }

    public void setAdditionRecoveryTime(long additionRecoveryTime) {
        if (additionRecoveryTime != this.additionRecoveryTime) {
            this.additionRecoveryTime = additionRecoveryTime;
            setUpdateOption();
        }
    }

    public String getUnionUid() {
        return unionUid;
    }

    public int getActivityId() {
        return activityId;
    }

    public Map<Long, Integer> getBuyTimesMap() {
        return buyTimesMap;
    }

    public Map<Integer, List<Long>> getRebateUserList() {
        return rebateUserList;
    }

    public Map<Integer, Integer> getCollectCountMap() {
        return collectCountMap;
    }

    public int getAddition() {
        return addition;
    }

    public long getAdditionRecoveryTime() {
        return additionRecoveryTime;
    }

    public int getBuyTimes() {
        int num = 0;
        for (int t : buyTimesMap.values()) {
            num += t;
        }
        return num;
    }

    public void addBuyTimes(long userId) {
        if (!buyTimesMap.containsKey(userId)) {
            buyTimesMap.put(userId, 0);
        }
        buyTimesMap.put(userId, buyTimesMap.get(userId) + 1);
        setUpdateOption();
    }

    public int getGroupId() {
        return groupId;
    }

    public void setGroupId(int groupId) {
        if (this.groupId != groupId) {
            this.groupId = groupId;
            setUpdateOption();
        }
    }
}
